<?php

/**
 * College
 * @property	int		$id
 * @property	string	$name
 * @property	string	$address
 * @property	string	$created
 * @property	string	$updated
 */
class College extends Node
{
    public static function option() {
        return array(
            'table' => 'College',
            'key' => 'id',
            'columns' => array(
                'id' => 'id',
                'name' => 'name',
                'address' => 'address',
                'created' => 'created',
                'updated' => 'updated',
                'attributeData' => 'attributes',
            ));
    }
    public static function attributesList() {
        return [
            'id',
            'name',
            'address',
        ];
    }
    public function remove() {
        /**
         * @var Course  $course
         * @var CourseClass $courseClass
         * @var CourseSelection $courseSelection
         * @var StudentClass   $class
         * @var Teacher $teacher
         */
        $courses = Course::find(new Query('collegeId', $this->id), ['nolimit' => 1]);
        foreach ($courses as $course) $course->remove();
        $classes = StudentClass::find(new Query('collegeId', $this->id), ['nolimit' => 1]);
        foreach ($classes as $class) $class->remove();
        $teachers = Teacher::find(new Query('collegeId', $this->id), ['nolimit' => 1]);
        foreach ($teachers as $teacher) $teacher->collegeId = "";
        $this->delete();
    }
}